// created by noellynch
// Jun 4, 2009

package com.sceneworker.editors.glslshadereditor.uniformreps;

import java.util.ArrayList;

import javax.swing.JPanel;
import javax.swing.JTextField;

import com.jme.scene.state.GLSLShaderObjectsState;
import com.jme.util.shader.ShaderVariable;
import com.jme.util.shader.uniformtypes.ShaderVariableFloat4;
import com.myjavautils.swing.MigLayoutUtils;
import com.sceneworker.editors.glslshadereditor.UniformRepresentations.IUniformRepresentation;

public class Float4Rep extends BaseUniformRep implements IUniformRepresentation {

	public static final String NAME = "Float4";

	public Float4Rep() {
	}

	@Override
	public String getNameRep() {
		return NAME;
	}

	public void createUniform(GLSLShaderObjectsState cl_state, String str_name) {
		cl_state.setUniform(str_name, 0.0f, 0.0f, 0.0f, 0.0f);
	}

	public Class<?> getUniformClassRep() {
		return ShaderVariableFloat4.class;
	}

	public ArrayList<JTextField> getUIRep(ShaderVariable cl_v, JPanel cl_parentPanel) {
		ShaderVariableFloat4		lcl_v = (ShaderVariableFloat4)cl_v;
		
		JTextField		lcl_v1 = MigLayoutUtils.numberText(cl_parentPanel, "Value1", lcl_v.value1, false);
		JTextField		lcl_v2 = MigLayoutUtils.numberText(cl_parentPanel, "Value2", lcl_v.value2, true);
		JTextField		lcl_v3 = MigLayoutUtils.numberText(cl_parentPanel, "Value3", lcl_v.value3, false);
		JTextField		lcl_v4 = MigLayoutUtils.numberText(cl_parentPanel, "Value4", lcl_v.value4, true);
		
		return uiFields(lcl_v1, lcl_v2, lcl_v3, lcl_v4);
	}

	public String getValueRep(ShaderVariable cl_v) {
		ShaderVariableFloat4		lcl_v = (ShaderVariableFloat4)cl_v;
		return out(lcl_v.value1, lcl_v.value2, lcl_v.value3, lcl_v.value4);
	}

	public	void	updateFromUI(GLSLShaderObjectsState cl_shaderState, ArrayList<JTextField> cla_values, ShaderVariable cl_v) {
		cl_shaderState.setUniform(cl_v.name, 
				Float.parseFloat(cla_values.get(0).getText()), 
				Float.parseFloat(cla_values.get(1).getText()),
				Float.parseFloat(cla_values.get(2).getText()),
				Float.parseFloat(cla_values.get(3).getText()));
	}
}
